package com.java.simple.smallspring.context.annotation;

import cn.hutool.core.util.ClassUtil;
import com.java.simple.smallspring.beans.factory.config.BeanDefinition;
import com.java.simple.smallspring.stereotype.Component;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author zhoujunlin
 * @date 2022年09月27日 17:27
 * @desc
 */
public class ClassPathScanningCandidateComponentProvider {

    /**
     * 找到basePackage包下所有Component的类
     *
     * @param basePackage
     * @return
     */
    public Set<BeanDefinition> findCandidateComponents(String basePackage) {
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }

}
